<?php
	if ( strcasecmp( @ $_SERVER['REQUEST_METHOD'], 'POST' ) == 0 )
	{
		$vali = new ClassValidation();
		loadClass("feedback");
		$obj = new Feedback();
		$err=array();
		if($_POST['txtfullname']=="" )
		{
			$er=array('txtfullname'=> "Bạn chưa nhập tên");
			$err=array_merge($err,$er);
		}
		if($_POST['txtmessage']=="" )
		{
			$er=array('txtmessage'=>"Bạn chưa nhập lời nhắn");
			$err=array_merge($err,$er);
		}
		if($_POST['txtemail']=="" )
		{
			$er=array('txtemail'=>"Bạn chưa nhập địa chỉ email");
			$err=array_merge($err,$er);
		}
		else
		{
			if($vali->_checkEmail($_POST['txtemail'])==false)
			{
				$er=array('txtemail'=>"Email không đúng định dạng");
				$err=array_merge($err,$er);
			}
		}
		if(count($err)==0)
		{
			$obj->Name=$_POST['txtfullname'];
			$obj->Country=$_POST['txtaddress'];
			$obj->Phone=$_POST['txtphone'];
			$obj->Country=$_POST['txtcompany'];
			$obj->Email=$_POST['txtemail'];
			$obj->Comment=$_POST['txtmessage'];
			$obj->insert($conn);
			
			//sendEmail("thietho1982@yahoo.com", $obj->Email, $obj->Comment, "Thông tin liên hệ");
			//echo $to=$datasfist['ListEmail'];
			/*foreach($datasfist['ListEmail'] as $tomail)
			{
				$to=$tomail;
				$from=$obj->Email;
				$msg=$obj->Comment;
				$subject="Thông tin liên hệ";
				sendEmail($to, $from, $msg, $subject);
			}*/
			// multiple recipients
			//print_r($objMenu->ListEmail);
			//$to  = arrToList($objMenu->ListEmail,","); // note the comma
			/*$to = $objMenu->ListEmail;
			// subject
			$subject = 'Thông tin liên hệ';
			// message
			$message = $obj->Comment;
			
			// To send HTML mail, the Content-type header must be set
			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
			
			// Additional headers
			//$headers .= 'To: '. $to  . "\r\n";
			$headers .= 'From: '.$obj->Email. "\r\n";
			
			
			// Mail it
			mail($to, $subject, $message, $headers);*/
			
			$mail['from'] = $obj->Email;
			$mail['FromName'] = $obj->Name;
			$mail['to'] = $objMenu->ListEmail;
			$mail['name'] = "Support";
			$mail['subject'] =  "Thong tin lien he";
			$mail['body'] = $obj->Comment;
			$mailsmtp->sendMail($mail);
			alert("Gởi thông tin thành công, cảm ơn bạn đã liên hệ với chúng tôi!");
			linkto(HTTP_SERVER);
		}
	}
?>
<style>
.form_contact td
{
	border:none;	
}
.form_contact input
{
	width:200px;
}
</style>
<div class="ben-section">
    <div class=" ben-section-title"><?php echo $objMenu->getPath(""," - ",$lang)?></div>
    
    <div class=" ben-section-content">	
        <h2><?php echo $objMenu->MenuName?></h2>
        <div class="ben-editor">
            <?php echo $objMenu->MenuDetail?>
            <div class="form_contact">
                <h3>Form Liên hệ</h3>
                <form id="frmcontact" name="frmcontact" method="post">
                <table>
                    <tr>
                        <td width="15%">Họ tên:</td>
                        <td><input class="ben-textbox" type="text" id="txtfullname" name="txtfullname" value="<?php echo $_POST['txtfullname']?>"/><i class="error"><?php echo $err['txtfullname']?></i></td>
                    </tr>
                    <tr>
                        <td>Email</td>
                        <td><input class="ben-textbox" id="txtemail" name="txtemail" type="text" value="<?php echo $_POST['txtemail']?>" /><i class="error"><?php echo $err['txtemail']?></i></td>
                    </tr>
                    <tr>
                        <td>Công ty:</td>
                        <td><input class="ben-textbox" id="txtcompany" name="txtcompany" type="text" value="<?php echo $_POST['txtcompany']?>"/></td>
                    </tr>
                    <tr>
                        <td>Địa chỉ:</td>
                        <td><input class="ben-textbox" id="txtaddress" name="txtaddress" type="text" value="<?php echo $_POST['txtaddress']?>"/><i class="error"><?php echo $err['txtaddress']?></i></td>
                    </tr>
                    <tr>
                        <td>Điện thoại:</td>
                        <td><input class="ben-textbox"  id="txtphone" name="txtphone" type="text" value="<?php echo $_POST['txtphone']?>" /><i class="error"><?php echo $err['txtphone']?></i></td>
                    </tr>
                    <tr>
                        <td>Nội dung liên lạc:</td>
                        <td>
                            <textarea class="ben-textbox" id="txtmessage" name="txtmessage" rows="5"><?php echo $_POST['txtmessage']?></textarea><i class="error"><?php echo $err['txtmessage']?></i>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <a href="#" class="ben-button" onclick="document.forms['frmcontact'].submit();">Gửi</a>
                            <a href="#" class="ben-button" onclick="document.forms['frmcontact'].reset();">Hủy</a></center>
                        </td>
                    </tr>
                    
                </table>
                </form>
                
            </div>      
        </div>
        <div class="clearer">&nbsp;</div>        
    </div>
</div>

   	

            